/* Game.h
 * Game class is the controller of the game (MVC)
 *
 * Last Modified: 08.12.2014
 * Author: Guilherme S.G.
 *
 * TODO:
 */

#ifndef __JB_GAME_H__
#define __JB_GAME_H__

#include "Global.h"
#include "View.h"
#include "HandSeal.h"
#include "Ninja.h"

class Game
{
private:
    ALLEGRO_DISPLAY *screen;
    ALLEGRO_EVENT_QUEUE *eventQueue;
    ALLEGRO_TIMER *timer;
    
    View *currentView;
    Tree<ObjectRenderable*> renderTree;
    //VideoCapture *video;
    ResourceManager *resources;
    std::map<std::string,HandSeal*> handSeals;
    HandSeal *currentSeal;
    std::vector<Ninja*> ninjas;
    int playerSelection;
    
    unsigned int screenWidth;
    unsigned int screenHeight;
    unsigned int screenBPP;
    bool running;
    bool redraw;
    
    GAME_SCREEN previousScreen;
    GAME_SCREEN currentScreen;
    GAME_SCREEN nextScreen;
    
public:
    Game(const int screenWidth_, const int screenHeight_, const int flags_);
    ~Game();
    
    void mainLoop();
    unsigned int getScreenWidth()       {return screenWidth;}
    unsigned int getScreenHeight()      {return screenHeight;}
    ResourceManager* getResources()     {return resources;}
    ALLEGRO_DISPLAY* getDisplay()       {return screen;}
    
    void setNextView(GAME_SCREEN nextScreen)
    {
        this->nextScreen = nextScreen;
    }
    
    void goToPreviousView()
    {
        this->nextScreen = this->previousScreen;
    }
    
    HandSeal* getSealWithName(std::string name_)
    {
        std::map<std::string,HandSeal*>::iterator it;
        
        it = handSeals.find(name_);
        
        return it->second;
    }
    
    HandSeal* getCurrentSeal()              {return currentSeal;}
    std::map<std::string, HandSeal*>& getSealMap()  {return handSeals;}
    
    void addNinja(Ninja *loadedNinja_)
    {
        ninjas.push_back(loadedNinja_);
    }
    
    Ninja *getNinja(int id_)    {return ninjas[id_];}
    int getNumberNinjas()       {return (int)ninjas.size();}
    
    void setPlayerSelection(int selection_)
    {
        playerSelection = selection_;
    }
    
    int getPlayerSelection()    {return playerSelection;}
    
    
   /* VideoCapture* getVideo()   {return video;}
    
    int getCurrentColor()   {return color;}
    void increaseCurrentColor() {color++;}
    void setCalibrate(bool set_)    {calibrate = set_;}*/
};

extern Game *controller;


#endif
